package com.example.mptnet.Adapters;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.mptnet.Models.RP;
import com.example.mptnet.R;

import java.util.ArrayList;

public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.ViewHolder> {
    private Context context;
    private ArrayList<RP> rplist;

    public RecyclerViewAdapter(Context context, ArrayList<RP> rplist){
        this.context = context;
        this.rplist = rplist;
    }

    @NonNull
    @Override
    public RecyclerViewAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.rp_card,parent,false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerViewAdapter.ViewHolder holder, int position) {
        RP rp = rplist.get(position);
        holder.title.setText("Расписание на " + rp.getWeekday());
        holder.rptext.setText(rp.get_rp());
    }

    @Override
    public int getItemCount() {
        return rplist.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView title;
        TextView rptext;
        public ViewHolder(@NonNull View itemview){
            super(itemview);
            title = itemview.findViewById(R.id.titleRP);
            rptext = itemview.findViewById(R.id.textRP);
        }
    }
}
